<?php
header('Content-Type: text/plain');
require_once dirname(__FILE__) . '/../../../incls/php/dbutils.class.php';
require_once dirname(__FILE__) . '/../../../incls/php/miscutils.class.php';
require_once dirname(__FILE__) . '/../../../incls/php/config.php';
session_name(SESSION);
session_start();
$myPdo = DbUtils::createPdoInst();
$action = $_POST['action'];
try {
  $myPdo->beginTransaction();
  switch ($action) {
    case 'save':
      save($myPdo);
      break;
    default:
      break;
  }
  $myPdo->commit();
} catch (PDOException $e) {
  echo $e->getMessage();
}

function save($myPdo) {
  if (!isset($_SESSION['admin' . USER])) {
    return;
  }
  $q = json_decode(MiscUtils::getParam('q', '[]'));
  if ($q->id == MEMBER_NORMAL_ID) {
    return;
  }
  if (isset($q->id)) {
    DbUtils::update($myPdo,  TABLE_NAME_PREFIX_PLUGIN . 'ecom_customer_member', $q);
  } else {
    DbUtils::add($myPdo,  TABLE_NAME_PREFIX_PLUGIN . 'ecom_customer_member', $q);
    $q->id = $myPdo->lastInsertId();
  }
  echo json_encode($q);
}

?>